package com.escape.subject.domain.handler.subject;

import com.escape.subject.common.enums.IsDeletedEnum;
import com.escape.subject.common.enums.SubjectInfoTypeEnum;
import com.escape.subject.domain.convert.BriefSubjectConverter;
import com.escape.subject.domain.entity.SubjectInfoBO;
import com.escape.subject.domain.entity.SubjectOptionBO;
import com.escape.subject.infra.basic.entity.SubjectBrief;
import com.escape.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: escape_zebra
 * @CreateTime: 2024-12-26  11:54
 * @Description: 简答题目策略类
 * @Version: 1.0
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{

    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getSubjectType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectAnswer(subjectInfoBO.getSubjectAnswer());
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBrief.setIsDeleted(IsDeletedEnum.UN_DELETED.getCode());
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(SubjectInfoBO subjectInfoBO) {
        // 1. 查询简答答案
        SubjectBrief brief = new SubjectBrief();
        brief.setSubjectId(subjectInfoBO.getId());
        brief.setIsDeleted(IsDeletedEnum.UN_DELETED.getCode());
        SubjectBrief subjectBrief = subjectBriefService.queryByCondition(brief);

        // 2. 封装答案
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(subjectBrief.getSubjectAnswer());
        return subjectOptionBO;
    }
}
